package pe.edu.unmsm.fisi.sisconteg.repository.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import pe.edu.unmsm.fisi.sisconteg.domain.model.GradoTesis;
import pe.edu.unmsm.fisi.sisconteg.repository.dao.GradoTesisDAO;

@Repository
public class GradoTesisDAOImpl implements GradoTesisDAO {

	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public GradoTesis getxId(Integer idGradoTesis) throws DataAccessException {
		return (GradoTesis) sessionFactory.getCurrentSession().get(
				GradoTesis.class, idGradoTesis);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<GradoTesis> getListGradosTesis() throws DataAccessException {
		return sessionFactory.getCurrentSession()
				.createCriteria(GradoTesis.class).list();
	}

	@Override
	public GradoTesis getxNombre(String nombreGradoTesis)
			throws DataAccessException {
		return (GradoTesis) sessionFactory.getCurrentSession()
				.createCriteria(GradoTesis.class)
				.add(Restrictions.eq("nombreGradoTesis", nombreGradoTesis))
				.uniqueResult();
	}
}
